<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <style>

    </style>
</head>

<body>
    <div id="app">
        <p v-demo.a.b="str">123</p>
        <div v-demo>456</div>
        <hr>
        <p v-myshow="bool">123</p>
    </div>
</body>
<script>
    //全局自定义指令
    Vue.directive('demo1', {
        bind(el, binding) {
            console.log(el, binding)
            if (binding.modifiers.a && binding.modifiers.a) {

                el.innerHTML = binding.value //通过指令操作dom
            }
        },
    })

    var vm = new Vue({
        el: '#app',
        data: {
            str: 'hello',
            bool: false
        },
        //局部
        directives: {
            demo(el, binding) {
                console.log(el, binding)
                if (binding.modifiers.a && binding.modifiers.a) {

                    el.innerHTML = binding.value //通过指令操作dom
                }
            },
            myshow(el, binding) {
                if (binding.value) { //控制要不要显示
                    el.style.display = ''
                } else {
                    el.style.display = 'none'
                }
            }
        }
    })
</script>

</html>